package geo.obj;

import java.awt.Polygon;
import geo.math.GMath;

public class Triangle implements IObject {
	private double[] _x;
	private double[] _y;
	private double _px;
	private double _py;
	private double _phi;
	GMath _g = new GMath();
	
	public Triangle(double[] x, double[] y, double px, double py, double phi){
		this._x = x;
		this._y = y;
		this._px = px;
		this._py = py;
		this._phi = phi;
	}
	
	public void setX(double[] aX) {
		this._x = aX;
	}

	public double[] getX() {
		return this._x;
	}

	public void setY(double[] aY) {
		this._y = aY;
	}

	public double[] getY() {
		return this._y;
	}

	public void setPx(double aPx) {
		this._px = aPx;
	}

	public double getPx() {
		return this._px;
	}

	public void setPy(double aPy) {
		this._py = aPy;
	}

	public double getPy() {
		return this._py;
	}

	public double getPhi() {
		return this._phi;
	}

	public boolean translate(double aX, double aY) {
		throw new UnsupportedOperationException();
		//TODO
	}

	public boolean moveTo(double aX, double aY) {
		throw new UnsupportedOperationException();
		//TODO
	}

	public double culcSpace() {
		double a = GMath.length(_x[0], _y[0], _x[1], _y[1]);
		double b = GMath.length(_x[1], _y[1], _x[2], _y[2]);
		double c = GMath.length(_x[2], _y[2], _x[0], _y[0]);
		double p = (a + b + c) / 2;
		return Math.sqrt(p * (p - a) * (p - b) * (p - c)); //Geron
	}

	public boolean onBorder(double aX, double aY) {
		if (GMath.isOnLine(aY, aY, _x[0], _y[0], _x[1], _y[1]) || 
				GMath.isOnLine(aY, aY, _x[1], _y[1], _x[2], _y[2]) ||
				GMath.isOnLine(aY, aY, _x[2], _y[2], _x[0], _y[0])) return true;
		return false;
	}

	public boolean inside(double aX, double aY) {
		int x[] = {(int) _x[0], (int) _x[1], (int) _x[2]};
		int y[] = {(int) _y[0], (int) _y[1], (int) _y[2]};
		Polygon p = new Polygon(x, y, 3);
		
		if (p.contains(aY, aY)) return true;
		return false;
	}

	public boolean rotate(double aAngle) {
		throw new UnsupportedOperationException();
		//TODO
	}
	
	
	/**
	 * returns rounded to integer coordinates of x
	 */
	public int[] getIntX(){
		int[]x = new int[3];
		for (int i = 0; i < 3; i++){
			x[i] = (int)_x[i];
		}
		return x;
	}
	
	/**
	 * returns rounded to integer coordinates of y
	 * @return
	 */
	public int[] getIntY(){
		int[]y = new int[3];
		for (int i = 0; i < 3; i++){
			y[i] = (int)_y[i];
		}
		return y;
	}

}